(function () {
  function getPageWidth() {
    var width = (screen.width > 0 && (window.innerWidth > screen.width || window.innerWidth == 0)) ? screen.width : window.innerWidth;
    var height = (screen.height > 0 && (window.innerWidth > screen.height || window.innerHeight == 0)) ? screen.height : window.innerHeight;
    if (width > height) width = height;
    return width;
  }

  function adjustForWebviewTextZoom(w, fontSize) {
    document.head.style.width = '6.4rem';
    var headWidth = parseInt(getComputedStyle(document.head).width);
    if(headWidth > 0 && headWidth != w && fontSize != 160) {
      fontSize *= w / headWidth;
      document.getElementsByTagName('html')[0].style.fontSize = fontSize + 'px';
    }
  }
  var w = getPageWidth(),
      fontSize = w > 1024 ? 160 : w / 6.4;
  document.getElementsByTagName('html')[0].style.fontSize = fontSize + 'px';
  adjustForWebviewTextZoom(w, fontSize);
})();